package com.example.designModel.原型模式.base;

import java.io.Console;

/**
 * XXXXXXXXX
 *
 * @author brad zhang
 * @version 2.0
 * @date 2021/11/17 17extends02
 */
public class Program {

    public static void main(String[] args) throws CloneNotSupportedException {
        ConcretePrototype1 p1 = new ConcretePrototype1("I");
        ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
        System.out.printf("Cloned: %s", c1.getIdP());
        System.out.println();
        ConcretePrototype2 p2 = new ConcretePrototype2("II");
        ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();
        System.out.printf("Cloned: %s", c2.getIdP());
        System.out.println();
    }
}

abstract class Prototype implements Cloneable {

    private String id;

    // Constructor
    public Prototype(String id) {
        this.id = id;
    }

    // Property
    public String IdP;

    public String getIdP() {
        return id;
    }

    public abstract Prototype Clone() throws CloneNotSupportedException;
}

class ConcretePrototype1 extends Prototype {

    // Constructor
    public ConcretePrototype1(String id) {
        super(id);
    }

    public Prototype Clone() throws CloneNotSupportedException {
        // Shallow copy
        return (Prototype)this.clone();
    }
}
class ConcretePrototype2 extends Prototype {

    // Constructor
    public ConcretePrototype2(String id){
        super(id);
    }


    public Prototype Clone() throws CloneNotSupportedException {
        // Shallow copy
        return (Prototype)this.clone();
    }
}